package com.whm.hrmanagement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.whm.common.annotation.Log;
import com.whm.common.core.controller.BaseController;
import com.whm.common.core.domain.AjaxResult;
import com.whm.common.enums.BusinessType;
import com.whm.hrmanagement.domain.OaSalaryDeduct;
import com.whm.hrmanagement.service.IOaSalaryDeductService;
import com.whm.common.utils.poi.ExcelUtil;
import com.whm.common.core.page.TableDataInfo;

/**
 * 工资扣除Controller
 * 
 * @author whm
 * @date 2024-02-09
 */
@RestController
@RequestMapping("/hrmanagement/deduct")
public class OaSalaryDeductController extends BaseController
{
    @Autowired
    private IOaSalaryDeductService oaSalaryDeductService;

    /**
     * 查询工资扣除列表
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:deduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaSalaryDeduct oaSalaryDeduct)
    {
        startPage();
        List<OaSalaryDeduct> list = oaSalaryDeductService.selectOaSalaryDeductList(oaSalaryDeduct);
        return getDataTable(list);
    }

    /**
     * 导出工资扣除列表
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:deduct:export')")
    @Log(title = "工资扣除", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaSalaryDeduct oaSalaryDeduct)
    {
        List<OaSalaryDeduct> list = oaSalaryDeductService.selectOaSalaryDeductList(oaSalaryDeduct);
        ExcelUtil<OaSalaryDeduct> util = new ExcelUtil<OaSalaryDeduct>(OaSalaryDeduct.class);
        util.exportExcel(response, list, "工资扣除数据");
    }

    /**
     * 获取工资扣除详细信息
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:deduct:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(oaSalaryDeductService.selectOaSalaryDeductById(id));
    }

    /**
     * 新增工资扣除
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:deduct:add')")
    @Log(title = "工资扣除", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaSalaryDeduct oaSalaryDeduct)
    {
        return toAjax(oaSalaryDeductService.insertOaSalaryDeduct(oaSalaryDeduct));
    }

    /**
     * 修改工资扣除
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:deduct:edit')")
    @Log(title = "工资扣除", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaSalaryDeduct oaSalaryDeduct)
    {
        return toAjax(oaSalaryDeductService.updateOaSalaryDeduct(oaSalaryDeduct));
    }

    /**
     * 删除工资扣除
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:deduct:remove')")
    @Log(title = "工资扣除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(oaSalaryDeductService.deleteOaSalaryDeductByIds(ids));
    }
}
